<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="ID">
            <el-input v-model="form.id" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="任务id" prop="taskId">
            <el-input v-model="form.taskId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="所属汇总进度表">
            <el-input v-model="form.collectId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="自我评定的任务完成进度">
            <el-input v-model="form.progress" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="更新时间">
            <el-input v-model="form.updateTime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="完成此项工作的地点">
            <el-input v-model="form.address" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="本周此项目耗时" prop="timeUse">
            <el-input v-model="form.timeUse" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column v-if="columns.visible('id')" prop="id" label="ID" />
        <el-table-column v-if="columns.visible('taskId')" prop="taskId" label="任务id" />
        <el-table-column v-if="columns.visible('collectId')" prop="collectId" label="所属汇总进度表" />
        <el-table-column v-if="columns.visible('progress')" prop="progress" label="自我评定的任务完成进度" />
        <el-table-column v-if="columns.visible('updateTime')" prop="updateTime" label="更新时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.updateTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="columns.visible('address')" prop="address" label="完成此项工作的地点" />
        <el-table-column v-if="columns.visible('timeUse')" prop="timeUse" label="本周此项目耗时" />
        <el-table-column v-permission="['admin','taskProgress:edit','taskProgress:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudTaskProgress from '@/api/taskProgress'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

// crud交由presenter持有
const defaultCrud = CRUD({ title: '研发任务进度', url: 'api/taskProgress', sort: 'id,desc', crudMethod: { ...crudTaskProgress }})
const defaultForm = { id: null, taskId: null, collectId: null, progress: null, updateTime: null, address: null, timeUse: null }
export default {
  name: 'TaskProgress',
  components: { pagination, crudOperation, udOperation },
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
  data() {
    return {
      permission: {
        add: ['admin', 'taskProgress:add'],
        edit: ['admin', 'taskProgress:edit'],
        del: ['admin', 'taskProgress:del']
      },
      rules: {
        taskId: [
          { required: true, message: '任务id不能为空', trigger: 'blur' }
        ],
        timeUse: [
          { required: true, message: '本周此项目耗时不能为空', trigger: 'blur' }
        ]
      }}
  },
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
